package com.labofjet.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.labofjet.entity.House;
import com.labofjet.repository.module2.HouseRepository;

@Service
public class TestTransactionService1 {
    @Autowired
    TestTransactionService2 service;
    
    @Autowired
    private HouseRepository repository;
    

    @Transactional(propagation = Propagation.REQUIRED)
    public void operate1() {
        House s = new House();
        s.setName("841o1");
        repository.save(s);
        try{
            service.operate2();
        }catch (Exception e) {
            e.printStackTrace();
        }
        House s3 = new House();
        s3.setName("843o1");        
        repository.save(s3);
        throw new RuntimeException();
    }
    
    @Transactional(propagation = Propagation.REQUIRED)
    public void deleteAll() {
        repository.deleteAll();
    }

    @Transactional(propagation = Propagation.REQUIRED)
    public void operate3() {
        House s = new House();
        repository.save(s);
        s.setName("abc");
        repository.save(s);
    }
}
